"use strict";
var loading = !1,
app = new Vue({
	el: "#app",
	data: {
		itabs: [{
			name: '协会动态',
			type: 1
		},
		{
			name: '企业动态',
			type: 2
		},
		{
			name: '本地新闻',
			type: 3
		},
		{
			name: '政策动态',
			type: 4
		}],
		tabs: [{
			name: "全部时间",
			id: 0
		},
		{
			name: "最近一月",
			id: 1
		}],
		tabContents: ["内容一", "内容二", "内容三", "没有内容了"],
		num: 0,
		num2: 0,
		listTab: [],
		Type: 0,
		hideing: !0,
		types: 1,
		pageIndex: 1,
		pageSize: 10,
		userId: 0,
		cityId: 0,
	},
	created: function() {
		if ("" != $.getPara("userId")) {
			var t = $.getPara("userId");
			this.userId = t,
			$.setStorage("userId", t)
		} else if ($.getStorage("userId") && "" != $.getStorage("userId")) {
			t = parseInt($.getStorage("userId"));
			this.userId = t
		}
		if ($.getPara('cityId')) {  //获取分享的参数
            this.cityId = $.getPara('cityId');
        }
		$.GetRequest().types && (this.types = $.GetRequest().types);
		var e = $.getPara("cityId");
		e ? this.cityId = e: $.toast("未获取分站城市的ID", "text"),
		this.getList()
	},
	mounted: function() {
		var e = this;
		this.$nextTick(function() {
			$(document.body).infinite().on("infinite",
			function() {
				loading || (loading = !0, e.hideing = !1, setTimeout(function() {
					var t = e.pageIndex;
					t++,
					e.pageIndex = t,
					e.getList(),
					loading = !1
				},
				1500))
			})
		})
	},
	methods: {
		backTop: function() {
			window.history.go( - 1)
		},
		getList: function() {
			var n = this;
			var tab = 0;
			if (n.types == 1) {
				tab = 3
			} else if (n.types == 2) {
				tab = 1
			} else if (n.types == 3) {
				tab = 2
			} else if (n.types == 4) {
				tab = 4
			}
			$.ajax({
				url: "/api/dynamic/list",
				type: 'get',
				dataType: 'json',
				data: {
					type: tab,
					timeType: n.Type,
					cityId: n.cityId,
					pageIndex: n.pageIndex,
					pageSize: n.pageSize
				},
				success: function(t, e, i) {
					if (200 == t.code) {
						var s = t.data.list;
						if (0 < s.length) {
							var a = n.listTab.concat(s);
							n.listTab = a
						} else loading = !0;
						n.hideing = !0
					}
				},
				error: function() {
					$.toast("加载失败，请重试", "text")
				}
			})
		},
		tab: function(t) {
			t != this.types && (this.types = t, this.Type = 0, this.pageIndex = 1, this.listTab = [], this.getList())
		},
		tab2: function(t) {
			t != this.Type && (this.Type = t, this.pageIndex = 1, this.listTab = [], this.getList())
		},
		urlHref: function(t) {
			var e = this,
			i = {};
			2 == e.types && (i.title = "企业动态详情"),
			3 == e.types && (i.title = "本地新闻详情"),
			1 == e.types && (i.title = "协会动态详情"),
			4 == e.types && (i.title = "政策动态详情"),
			i.type = "dynamic",
			i.url = "/PageClassify/html/Substation/Dynamic/subDynamicDetails.html?id=" + t.id + "&types=" + e.types +"&cityId="+e.cityId,
			0 < this.userId && (i.url = "/PageClassify/html/Substation/Dynamic/subDynamicDetails.html?id=" + t.id + "&userId=" + this.userId + "&types=" + e.types+"&cityId="+e.cityId),
			/(Android)/i.test(navigator.userAgent) ? jsAndroid.appPush(JSON.stringify(i)) : /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ? window.webkit.messageHandlers.appPush.postMessage(i) : window.location.href = i.url
		}
	}
});